<?php

namespace App\Http\Controllers\Api;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\Menu;

class MenusController extends Controller
{
    /**
     *
     * @api {get} /v1/menus 获取菜单
     *
     *
     * @apiName GetMenus
     * @apiGroup Menus
     * @apiHeader {String} Authorization Bearer $accesstoken(Bearer和$accesstoken之间有一个空格)
     * @apiHeader {String} Accept application/json
     *
     * @apiSuccess {Number} code 返回码.
     * @apiSuccess {String} msg 消息
     * @apiSuccess {Array[]} data 返回数据.
     * @apiSuccess {String} data.name 菜单分组名
     * @apiSuccess {Number} data.pid 菜单父级ID
     * @apiSuccess {String} data.permission_name 菜单权限组名
     * @apiSuccess {Array[]} data.downMenu 下级菜单
     * @apiSuccess {Number} data.downMenu.id 菜单ID
     * @apiSuccess {Number} data.downMenu.pid 子菜单的父id
     * @apiSuccess {String} data.downMenu.name 子菜单的名字
     * @apiSuccess {String} data.downMenu.permission_name 子菜单的菜单权限组名
     * @apiSuccess {Number} data.downMenu.sort 子菜单的菜单排序
     * @apiSuccess {Number} data.downMenu.status 子菜单的菜单状态0正常1禁用
     * @apiSuccess {Array[]} data.downMenu.permission 子菜单的菜单权限
     * @apiSuccess {Number} data.downMenu.permission.create 当前用户子菜单的创建权限
     * @apiSuccess {Number} data.downMenu.permission.show 当前用户子菜单的查看权限
     * @apiSuccess {Number} data.downMenu.permission.edit 当前用户子菜单的编辑权限
     * @apiSuccess {Number} data.downMenu.permission.destroy 当前用户子菜单的删除权限
     *
     *
     *
     * @apiSuccessExample {json} Success-Response:
     *     HTTP/1.1 200 OK
    {
        "code": 0,
        "msg": "成功!",
        "data": [
            {
                "name": "首页",
                "pid": 1,
                "permission_name": "index",
                "downMenu": [
                {
                    "id": 11,
                    "pid": 3,
                    "name": "首页",
                    "permission_name": "index-index",
                    "sort": 1,
                    "status": 0,
                    "is_menu": 0,
                    "permission": {
                        "create": "0",
                        "show": "0",
                        "edit": "0",
                        "destroy": "0"
                        }
                    }
                    ]
                },
                {
                "name": "城市管理",
                "pid": 1,
                "permission_name": "city",
                "downMenu": [
                {
                    "id": 6,
                    "pid": 4,
                    "name": "建筑列表",
                    "permission_name": "city-building",
                    "sort": 1,
                    "status": 0,
                    "is_menu": 0,
                    "permission": {
                        "create": "0",
                        "show": "0",
                        "edit": "0",
                        "destroy": "0"
                    }
                },
                {
                    "id": 7,
                    "pid": 4,
                    "name": "截图列表",
                    "permission_name": "city-screenshot",
                    "sort": 2,
                    "status": 0,
                    "is_menu": 0,
                    "permission": {
                        "create": "0",
                        "show": "0",
                        "edit": "0",
                        "destroy": "0"
                    }
                },
                {
                    "id": 8,
                    "pid": 4,
                    "name": "行走轨迹",
                    "permission_name": "city-walking",
                    "sort": 3,
                    "status": 0,
                    "is_menu": 0,
                    "permission": {
                        "create": "0",
                        "show": "0",
                        "edit": "0",
                        "destroy": "0"
                    }
                }
                ]
                },
                {
                "name": "账号管理",
                "pid": 1,
                "permission_name": "user",
                "downMenu": [
                {
                    "id": 10,
                    "pid": 5,
                    "name": "账号管理",
                    "permission_name": "user-manage",
                    "sort": 1,
                    "status": 0,
                    "is_menu": 0,
                    "permission": {
                        "create": "0",
                        "show": "0",
                        "edit": "0",
                        "destroy": "0"
                    }
                },
                {
                    "id": 9,
                    "pid": 5,
                    "name": "账号列表",
                    "permission_name": "user-list",
                    "sort": 2,
                    "status": 0,
                    "is_menu": 0,
                    "permission": {
                        "create": "0",
                        "show": "0",
                        "edit": "0",
                        "destroy": "0"
                    }
                }
                ]
            }
        ]
    }
     *
     *
     *
     * @apiError {Number} code 返回码.
     * @apiError {String} msg 消息
     * @apiError {Array[]} data 返回为空.
     * @apiErrorExample  {json} Error-Response:
     *     HTTP/1.1 200 OK
    {
    "code": "10001",
    "msg": "系统内部错误",
    "data": {}
    }
     *
     *
     */
    public function index()
    {
        $menu = new Menu();
        $menus = $menu->getMenus();

//        return response()->json($menus, '200', ['Access-Control-Allow-Origin' => '*']);



        if ($menus){
             $ret = $this->display(0,$menus);
        }else{
            $ret = $this->display('10001',$menus);
        }
        return $ret;

    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}
